package com.muyu.danmo.util;

import com.muyu.danmo.domain.DanmoInformation;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * 百家姓 BaiJiaXing
 *
 * @author LeYang
 * on 2024/12/6
 */
public class BaiJiaXing {
    // 百家姓顺序列表
    private static final List<String> BAIJIA_XING = Arrays.asList(

    );

    // 方法：根据百家姓排序 List<DanmoInformation>
    public List<DanmoInformation> sortDanmoInformationByBaijiaxing(List<DanmoInformation> danmoInformations) {
        danmoInformations.sort(new Comparator<DanmoInformation>() {
            @Override
            public int compare(DanmoInformation o1, DanmoInformation o2) {
                String name1 = o1.getName();
                String name2 = o2.getName();

                // 获取姓氏（假设姓氏为名字的第一个字符）
                String surname1 = name1.substring(0, 1);
                String surname2 = name2.substring(0, 1);

                // 比较姓氏在百家姓中的顺序
                int index1 = BAIJIA_XING.indexOf(surname1);
                int index2 = BAIJIA_XING.indexOf(surname2);

                return Integer.compare(index1, index2);
            }
        });
        return danmoInformations;
    }
}
